package com.springlearn.springsourcecode.chap6;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import javax.annotation.PostConstruct;

/**
 * @author wtcode
 * @Description
 * @date 2025/3/31 - 9:57
 */
public class MyBean implements BeanNameAware, ApplicationContextAware, InitializingBean {

    public static final Logger log = LoggerFactory.getLogger(BeanNameAware.class);

    @Override
    public void setBeanName(String s) {
        log.debug("当前bean" + this + "名字叫:{}",s);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        log.debug("当前bean" + this + "容器是:{}",applicationContext);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        log.debug("当前bean" + this + "初始化");
    }

    @Autowired
    public void aaa(ApplicationContext applicationContext){
        log.debug("当前bean" + this + "使用@Autowired注解容器是:{}",applicationContext);

    }

    @PostConstruct
    public void init(){
        log.debug("当前bean" + this + "使用@PostConstruct初始化");
    }
}
